﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Pharmacy_management_system
{
    public partial class YiShengZiDian2 : Form
    {
        public YiShengZiDian2()
        {
            InitializeComponent();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            button5.Visible = true;
            string row1 = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0].Value.ToString();//获取datagridview1的第一列
            string row2 = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[1].Value.ToString();//获取datagridview1的第2列
            string row3 = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[2].Value.ToString();//获取datagridview1的第2列

            DataTable dt = new DataTable();

            DataColumn dc_t = new DataColumn("姓名", Type.GetType("System.String"));
            DataColumn dc_u = new DataColumn("检索码", Type.GetType("System.String"));
            DataColumn dc_p = new DataColumn("科室", Type.GetType("System.String"));
            dt.Columns.Add(dc_t);
            dt.Columns.Add(dc_u);//在datatable中定义列名：username和password. 
            dt.Columns.Add(dc_p);


            DataRow dr = dt.NewRow();
            dr["姓名"] = row1;
            dr["检索码"] = row2;//将在datagridview1中获得的两列：row1/row2分别存放在datatable中对应的username和password列
            dr["科室"] = row3;

            dt.Rows.Add(dr);//至此，datatable已经存放了从datagridview1中获得的所有数据。
            dataGridView2.DataSource = dt;//datatable作为datagridview2的数据源
        }

        private void YiShengZiDian2_Load(object sender, EventArgs e)
        {
            string sql = @"server=.;database=PASS;Integrated Security=True";
            string sqlstr = "select doctor_name as 姓名,py_code as 检索码,dept_name as 科室 from dict_doctor";
            SqlConnection conn = new SqlConnection(sql);
            conn.Open();
            SqlDataAdapter df = new SqlDataAdapter(sqlstr, conn);
            DataSet ds = new DataSet();
            df.Fill(ds, "dict_doctor");
            DataTable dt1 = new DataTable();
            dt1 = ds.Tables["dict_doctor"];
            dataGridView1.DataSource = ds;
            dataGridView1.DataMember = "dict_doctor";
            conn.Close();//以上内容都是将数据库的内容显示在 dataGridView1中  
        }
    }
}
